import { defineStore } from 'pinia'
import { setLanguage } from '../plugin/i18n'
import { storageDict } from '@/config/dict'
import { useUserStore } from './user'

export const useMainStore = defineStore('main', {
  state: () => {
    return {
      /**
       * 当前语言
       */
      language: localStorage.getItem(storageDict.LANGUAGE),
      /**
       * 语言列表
       */
      languageList: ['zh', 'en'],
      /**
       * 格式化
       */
      timeFormat: 'MM/DD/YYYY',
      /**
       * 验证码地址
       */
      verificationCodeUrl: `${__config._BASE_API}/user/api/user/easyGenerateCode`,
    }
  },
  getters: {
  },
  actions: {


    /**
     * 设置 语言
     * @param {*} language
     */
    setLanguage(language) {
      if (this.language != language) {
        this.language = language
        localStorage.setItem(storageDict.LANGUAGE, language)
        setLanguage(language)
        // let tempObj = this.languageList.find((elem) => elem.language == this.language)
        // 触发事件
      }
    },
  },
  // 开启数据持久化
  // persist: true
  // 持久化存储插件其他配置
  persist: {
    paths: ['settingConfig']
  }
})
